﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using NTwitter;
using System.Collections.ObjectModel;
using TwitterClient2.Controller;
using System.Drawing;

namespace TwitterClient2.Components
{
    public class PanelHome : Panel
    {
        private Label labelUpdateStatus;
        private TextBox textBoxUpdate;
        private Label labelWordCount;
        private PanelTweetOverview panelTweetOverview;
        private Button updateButton;
        private PanelNavigation panelNavigation;
        private TwitterClientController controller = TwitterClientController.getInstance();
        public PanelHome()
        {
            InitializeComponent();
        }
        private void InitializeComponent()
        {
            this.labelUpdateStatus = new System.Windows.Forms.Label();
            this.updateButton = new System.Windows.Forms.Button();
            this.textBoxUpdate = new System.Windows.Forms.TextBox();
            this.labelWordCount = new System.Windows.Forms.Label();
            this.panelTweetOverview = new TwitterClient2.Components.PanelTweetOverview(120, PanelNavigation.HOME_USER);
            this.panelNavigation = new PanelNavigation("Home", PanelNavigation.PANEL_HOME);
            this.SuspendLayout();
            // 
            // labelUpdateStatus
            // 
            this.labelUpdateStatus.Location = new System.Drawing.Point(10, 20);
            this.labelUpdateStatus.Name = "labelUpdateStatus";
            this.labelUpdateStatus.Size = new System.Drawing.Size(150, 20);
            this.labelUpdateStatus.Text = "What are you doing?";
            // 
            // updateButton
            // 
            this.updateButton.Location = new System.Drawing.Point(153, 110);
            this.updateButton.Name = "updateButton";
            this.updateButton.Size = new System.Drawing.Size(72, 20);
            this.updateButton.Click += new EventHandler(this.updateButtonClick);
            this.updateButton.TabIndex = 0;
            this.updateButton.Text = "update";
            // 
            // textBoxUpdate
            // 
            this.textBoxUpdate.Location = new System.Drawing.Point(10, 43);
            this.textBoxUpdate.MaxLength = 160;
            this.textBoxUpdate.Multiline = true;
            this.textBoxUpdate.Name = "textBoxUpdate";
            this.textBoxUpdate.Size = new System.Drawing.Size(220, 62);
            this.textBoxUpdate.TabIndex = 0;
            this.textBoxUpdate.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBobUpdateKeyPressed);
            // 
            // labelWordCount
            // 
            this.labelWordCount.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Bold);
            this.labelWordCount.Location = new System.Drawing.Point(195, 20);
            this.labelWordCount.Name = "labelWordCount";
            this.labelWordCount.Size = new System.Drawing.Size(30, 20);
            this.labelWordCount.Text = "160";
            // 
            // panelTweetOverview
            // 
            this.panelTweetOverview.BackColor = System.Drawing.Color.Gainsboro;
            this.panelTweetOverview.Location = new System.Drawing.Point(10, 140);
            this.panelTweetOverview.Name = "panelTweetOverview";
            this.panelTweetOverview.Size = new System.Drawing.Size(220, 120);
            //
            // PanelNavigation
            //
            this.panelNavigation.Location = new Point(10, 0);
            // 
            // PanelHome
            // 
            this.Controls.Add(this.updateButton);
            this.Controls.Add(this.labelUpdateStatus);
            this.Controls.Add(this.textBoxUpdate);
            this.Controls.Add(this.labelWordCount);
            this.Controls.Add(this.panelTweetOverview);
            this.Controls.Add(this.panelNavigation);
            this.ResumeLayout(false);

        }

        public void UpdateData(Collection<Status> c)
        {
            this.panelTweetOverview.UpdateData(c);
        }

        private void textBobUpdateKeyPressed(object sender, KeyEventArgs e)
        {
            int length = 160 - this.textBoxUpdate.Text.Length;
            this.labelWordCount.Text = length + "";
        }

        private void updateButtonClick(object sender, EventArgs e)
        {
            TwitterClientEvent tEvent = new TwitterClientEvent();
            if (this.textBoxUpdate.Text.Length > 0)
            {
                Cursor.Current = Cursors.WaitCursor;
                tEvent.paramList.Add(this.textBoxUpdate.Text);
                this.controller.performUserInput(TwitterClientController.UPDATE_STATUS_CLICK, tEvent);
                Cursor.Current = Cursors.Default;
            }
        }

    }
}
